package com.flow.demo.module.system.controller.app.login;

import cn.hutool.core.util.StrUtil;
import com.flow.demo.framework.common.pojo.CommonResult;
import com.flow.demo.framework.operatelog.core.annotations.OperateLog;
import com.flow.demo.framework.security.config.SecurityProperties;
import com.flow.demo.framework.security.core.util.SecurityFrameworkUtils;
import com.flow.demo.module.system.controller.admin.auth.vo.AuthLoginRespVO;
import com.flow.demo.module.system.controller.app.login.vo.LoginPhoneVo;
import com.flow.demo.module.system.controller.app.login.vo.LoginWxPhoneVo;
import com.flow.demo.module.system.controller.app.login.vo.WechartcodeVo;
import com.flow.demo.module.system.enums.logger.LoginLogTypeEnum;
import com.flow.demo.module.system.service.auth.AdminAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import static com.flow.demo.framework.common.pojo.CommonResult.success;

@Tag(name = "小程序 - 用户登录")
@RestController
@Validated
public class LoginController {

    @Resource
    private AdminAuthService authService;

    @Resource
    private SecurityProperties securityProperties;

    @PostMapping("/loginPhone")
    @Operation(summary = "手机号")
    @PermitAll
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<AuthLoginRespVO> loginPhone(@Valid @RequestBody LoginPhoneVo reqVO) {
        return success(authService.loginPhone(reqVO));
    }


    @PostMapping("/loginWxPhone")
    @Operation(summary = "微信手机号")
    @PermitAll
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<AuthLoginRespVO> loginWxPhone(@Valid @RequestBody LoginWxPhoneVo reqVO) {
        return success(authService.loginWxPhone(reqVO));
    }




}
